package com.atguigu.tingshu.account.mq;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.model.account.UserAccount;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
@Slf4j
public class AccontReceiver {
    @Autowired
    UserAccountService userAccountService;
    @KafkaListener(topics = KafkaConstant.QUEUE_USER_REGISTER)
    public void initAccount(ConsumerRecord<String,String> record){
        String userId = record.value();
        if(!userId.isEmpty()){
            userAccountService.save(new UserAccount(Long.valueOf(userId), BigDecimal.valueOf(0), BigDecimal.valueOf(0), BigDecimal.valueOf(0), BigDecimal.valueOf(0), BigDecimal.valueOf(0)));
            log.info(userId+"用户注册成功，初始化账户成功");
        }
    }

}
